<?php

 /*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     function
 * Name:     cm_thumbnail
 * Version:  0.1
 * Date:     September 9, 2002
 * Author:	 Alexei Saveliev <alexei@saveliev.org>
 * Purpose:  display thumbnail
 * Input:    content_id = id of content
 * Input:    gallery_id = id of gallery
 * 
 * Examples: {cm_thumbnail category_id=9 gallery_id=10 content_id=11}
 * -------------------------------------------------------------
 */

function smarty_function_cm_thumbnail($params, &$smarty)
{
	global $db_link,$thumb_cache;
	$gallery_id=(int)$params['gallery_id'];
	$content_id=(int)$params['content_id'];
	$category_id=(int)$params['category_id'];
	if (isset($thumb_cache[$content_id])){
		$th=&$thumb_cache[$content_id];
	}else{
		$sql='SELECT c.content_id,c.content_file,c.content_ver_main,c.content_ver_thumb,c.content_size,c.thumbnail_size,c.thumbnail_width,c.thumbnail_height,c.gallery_id,c.content_description,ca.category_name,CONCAT(ca.category_path,g.gallery_description_url,"/",ca.category_id,"/",g.gallery_id,"/",c.content_id,"/") AS content_path FROM content c LEFT JOIN galleries g ON g.gallery_id=c.gallery_id LEFT JOIN categories_galleries cg ON cg.gallery_id=g.gallery_id LEFT JOIN categories ca ON cg.category_id=ca.category_id WHERE c.content_id="'.$content_id.'" AND ca.category_id="'.$category_id.'" AND g.gallery_id="'.$gallery_id.'"';
		if ($result=my_query($sql,$db_link)){
			if (mysql_num_rows($result)){
				$th=&mysql_fetch_assoc($result);
				$th['thumbnail_path']=CONTENT_URL.$th['content_path'].$th['content_ver_thumb'].'/thumbnail';
				$th['content_path']=CONTENT_URL.$th['content_path'].$th['content_ver_main'].'/'.$th['content_file'];
				$thumb_cache[$content_id]=&$th;
			}
			my_query_free($result);
		}
	}
	if (isset($th)){
		$smarty->assign('thumbnail',$th);
		$smarty->display('story_thumbnail.html');
	}
}

?>
